//
//  BoatAllianceViewController.m
//  shuiyun
//
//  Created by 徐双 on 2017/9/7.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "BoatAllianceViewController.h"
#import "RecommendViewController.h"
#import "BoatListViewController.h"

@interface BoatAllianceViewController ()<ZJScrollPageViewDelegate>

@property(strong, nonatomic)NSArray<NSString *> *titles;
@property(strong, nonatomic)NSArray<UIViewController<ZJScrollPageViewChildVcDelegate> *> *childVcs;
@end

@implementation BoatAllianceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"船方联盟"];
    
    //添加右侧导航栏按钮
    UIButton *buttonClick = [[UIButton alloc] init];
    
    buttonClick.frame = CGRectMake(DEF_SCREEN_WIDTH - 13, 0, 40, 40);
    
    [buttonClick setImage:[UIImage imageNamed:@"icon-_paihang"] forState:UIControlStateNormal];
    
    [buttonClick addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc]initWithCustomView:buttonClick];
    self.navigationItem.rightBarButtonItem = rightItme;
    
    //必要的设置, 如果没有设置可能导致内容显示不正常
    self.automaticallyAdjustsScrollViewInsets = NO;
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    style.scrollTitle = YES;
    style.autoAdjustTitlesWidth = YES;
    style.adjustCoverOrLineWidth = YES;
    style.selectedTitleColor = [UIColor colorWithRed:63 / 255.0f green:135 / 255.0f blue:246 / 255.0f alpha:1];
    style.scrollLineColor = [UIColor colorWithRed:63 / 255.0f green:135 / 255.0f blue:246 / 255.0f alpha:1];
    style.segmentHeight = 42;
    self.titles = @[@"所在地",
                    @"出发地",
                    @"长期货",
                    @"推荐货",
                    ];
   // self.childVcs = [self setupChildVc];
    
    // 初始化
    ZJScrollPageView *scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64.0) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    [scrollPageView setSelectedIndex:self.index animated:YES];
    scrollPageView.contentView.scrollView.scrollEnabled = YES;
    [self.view addSubview:scrollPageView];
    
    
}

-(void)btnClick{

    BoatListViewController * vc = [[BoatListViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];

}

#pragma mark ----------------ZJScrollPageViewDelegate---------------------
- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}



- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    
    RecommendViewController <ZJScrollPageViewChildVcDelegate> *childVc = (RecommendViewController *)reuseViewController;
    
    if (!childVc) {
        
        childVc = [[RecommendViewController alloc] init];
        
        childVc.orderStatus = index;
        
        
        //        childVc.orderStatus = [self.arrOfName objectAtIndex:index];
        
        
        //NSLog(@"AAAAAAAAAAAAAAA%@", childVc.orderStatus);
        
        
    }
    
    return childVc;
}
-(void)leftNavItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}




@end
